import BaseCURDV2Api from "@/framework/infra/base/BaseCURDV2Api";

class RoleApi extends BaseCURDV2Api {
  constructor() {
    super('mgr/role')
  }
  list(params) {
    const getParams = { ...params }
    Object.keys(getParams).forEach(key => {
      if (Array.isArray(getParams[key])) {
        getParams[key] = getParams[key].join(',')
      }
    })
    return this.post('list-page', getParams)
  }

  listAll = () => {
    return this.get('list-all')
  }

  permissionList(id) {
    return this.get('permission-list', {id})
  }

  permissionCodeList(id) {
    return this.get('permission-code-list', {id})
  }

  savePermissions(data) {
    return this.post('save-permissions', data)
  }
}

export const roleApi = new RoleApi()
